import ActionTypes from '../config/ActionTypes';

const initState = {
    isLoading:{
        newsCategory:false,
        todolist:false,
    },
    newsCategory:{
        items:[],
    },
    todoList:{
        items:[],
    }
}

const homeReducer = (state = initState, action) => {

    switch(action.type){
        case ActionTypes.NEWCATEGORYS + ActionTypes.FETCH_LOADING_SUFFIX:
        {
            return {
                ...state,
                isLoading:{
                    newsCategory:true
                }
            };
        }
        break;
        case ActionTypes.NEWCATEGORYS + ActionTypes.FETCH_SUCCESS_SUFFIX:
        {
            return {
                ...state,
                isLoading:{
                    newsCategory:false
                },    
                newsCategory:{
                    items:action.items,
                }
            };
        }
        break;
        case ActionTypes.NEWCATEGORYS + ActionTypes.FETCH_ERROR_SUFFIX:
        {
            return {
                ...state,
                isLoading:{
                    newsCategory:false
                }
            };
        }
        break;
        case ActionTypes.TODOLIST + ActionTypes.FETCH_LOADING_SUFFIX:
        {
            return {
                ...state,
                isLoading:{
                    todoList:true
                }
            };
        }
        break;
        case ActionTypes.TODOLIST + ActionTypes.FETCH_SUCCESS_SUFFIX:
        {
            return {
                ...state,
                isLoading:{
                    todoList:false
                },
                todoList:{
                    items:[],
                }
            };
        }
        break;
        case ActionTypes.TODOLIST + ActionTypes.FETCH_ERROR_SUFFIX:
        {
            return {
                ...state,
                isLoading:{
                    todoList:false
                }
            };
        }
        break;

        default:
        {
            return state;
        }
        break;
    }
}

export default homeReducer;